package com.yunshang.ysmall.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yunshang.ysmall.mapper.OrderItemInfoMapper;
import com.yunshang.ysmall.mapper.ProductInfoMapper;
import com.yunshang.ysmall.mapper.SupplierMapper;
import com.yunshang.ysmall.model.OrderItemInfo;
import com.yunshang.ysmall.model.ProductInfo;
import com.yunshang.ysmall.model.SupplierInfo;
import com.yunshang.ysmall.service.SupplierService;

@Service
public class SupplierServiceImpl implements SupplierService {
	
	@Resource
	SupplierMapper supplierMapper;
	@Resource
	OrderItemInfoMapper orderItemInfoMapper;
	@Resource
	ProductInfoMapper  productInfoMapper;

	@Override
	public void saveSupplierInfo(SupplierInfo supplierInfo) {
		supplierMapper.saveBySupplierInfo(supplierInfo);
	}

	@Override
	public List<SupplierInfo> findSupplierAll() {
		return supplierMapper.findSuppliers();
	}

	@Override
	public List<SupplierInfo> conditionQuerySupplier(SupplierInfo supplierInfo) {
		return supplierMapper.conditionQuerySupplierInfo(supplierInfo);
	}

	@Override
	public List<OrderItemInfo> findOrderItemList() {
		return orderItemInfoMapper.findOrderItemList();
	}

	@Override
	public SupplierInfo findSoleSupplier(String productId) {
		//首先根据商品id查询商品信息
		ProductInfo productInfo =productInfoMapper.selectByProId(productId);
		 if(productInfo==null){
			 return null;
		 }
		 SupplierInfo supplier=supplierMapper.findBySupplierId(productInfo.getSupplierId());
		 return supplier;
	}

	@Override
	public List<OrderItemInfo> findOrderItemInfos(Map<String, Object> parameter) {
		return orderItemInfoMapper.findOrderItemArray(parameter);
	}
		


}
